package com.cy.pj.arithmetic.controller;

import com.cy.pj.arithmetic.service.ArithmeticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ArithmeticController {

    //Controller类内部的异常处理方法
    // @ExceptionHandler注解描述的方法为异常处理方法
    // @ExceptionHandler注解内部定义的异常类型为它描述的方法可以处理的异常类型
//    @ResponseBody
//    @ExceptionHandler(ArithmeticException.class)
//    public String doHandleArithmeticException(ArithmeticException e){
//        return "the exception msg is"+e.getLocalizedMessage();
//    }

    @ResponseBody
    @RequestMapping("/doCompute/{n1}/{n2}")
    public String doController(@PathVariable Integer n1, @PathVariable Integer n2){

//        try {
            Integer result = n1/n2;
            return "The Tesult is"+result;
//        }catch (ArithmeticException e){
//            e.printStackTrace();
//            return "计算过程中出现异常，具体信息为："+e.getLocalizedMessage();
//        }

    }


    @Autowired
    private ArithmeticService arithmeticService;


    @RequestMapping("/doSum/{a}/{b}")
    public String doSum(@PathVariable Integer a, @PathVariable Integer b){
        return "求和结果"+ arithmeticService.Sum(a,b);
    }

//    @ResponseBody
//    @RequestMapping("/dosum/{nums}")
//    public String dosum(@PathVariable Integer ...nums){
//        return "求和结果为"+ arithmeticService.sum(nums);
//    }


}
